<route lang="json5" type="page">
{
  style: { navigationBarTitleText: '登录' },
}
</route>

<template>
  <view class="center pt-4 flex-col list-container">
    <view class="mb-3">
      <button type="primary" @click="login('AppIndexView')">登录并跳转首页</button>
    </view>
    <view class="mb-3">
      <button @click="login('MobViewTestMobMDView_confirm')">登录并跳转多数据视图</button>
    </view>
    <view class="mb-3">
      <button @click="login('MobViewTestMobEditView_confirm')">登录并跳转编辑视图</button>
    </view>
    <view class="mb-3">
      <button @click="login('viewtestusr09245675mobcustomview')">视图布局面板</button>
    </view>
    <view class="mb-3">
      <button @click="login('MobViewTestMobMDView_confirm')">多数据视图布局面板</button>
    </view>
  </view>
</template>

<script setup lang="ts">
import { IBizContext } from '@ibiz-template/core'
import { generateRoutePath } from '@/utils'
import { useUserStore } from '@/store'
import { AuthGuard } from '@/guard'

const userStore = useUserStore()

const login = async (viewId: string) => {
  const res = await ibiz.net.post('/v7/login', {
    loginname: 'preview_admin',
    password: '123456',
  })
  if (res.ok) {
    userStore.setUserInfo({
      nickname: 'preview_admin',
      avatar: '',
      token: res.data.token,
    })
  }
  await AuthGuard()
  const viewConfig = await ibiz.hub.config.view.get(viewId)
  const context = {
    ...ibiz.appData.context,
  }
  if (viewId === 'MobViewTestMobEditView_confirm') {
    context.mobviewtest = '050ab3632561ee38c8fad01f3093b2d7'
  }
  const { path } = await generateRoutePath(
    viewConfig,
    IBizContext.create({}, context),
    {},
    '/-/home/-',
  )
  uni.redirectTo({
    url: path,
  })
}
</script>

<style lang="scss" scoped>
//
</style>
